/*
 * @Author: your name
 * @Date: 2021-09-03 10:24:53
 * @LastEditTime: 2021-09-03 10:42:28
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day10\4-组合模式.js
 */

//通过构造函数放私有属性
function Person(name, age, gender) {
    this.name = name;
    this.age = age;
    this.gender = gender;
    this.likes = ["吃饭", "睡觉", "打篮球"];
}
//通过构造函数原型放公共属性
Person.prototype = {
        //原型里有个constructor指针指向构造函数
        constructor: Person,
        sayName: function() {
            console.log(this.name);
        }

    }
    //创建构造函数同时赋值
var p1 = new Person("terry", 12, "男");
var p2 = new Person("lucy", 15, "女");
p1.likes.push("打豆豆");
p2.likes.push("踢足球");
console.log(p1);
/*Person {
    name: 'terry',
    age: 12,
    gender: '男',
    likes: [ '吃饭', '睡觉', '打篮球', '打豆豆' ]
  }*/
console.log(p2);
/*Person {
    name: 'lucy',
    age: 15,
    gender: '女',
    likes: [ '吃饭', '睡觉', '打篮球', '踢足球' ]
  }*/